
#include"dropframe.h"
#include"convertmainwindow.h"

DropFrame::DropFrame(QWidget *parent) : QFrame(parent) {
    // 开启拖放功能
    setAcceptDrops(true);
}



void DropFrame::dragEnterEvent(QDragEnterEvent *event) {
    if (event->mimeData()->hasUrls()) {
        event->acceptProposedAction();
    } else {
        event->ignore();
    }
}

void DropFrame::dragMoveEvent(QDragMoveEvent *event) {
    if (event->mimeData()->hasUrls()) {
        event->acceptProposedAction();
    } else {
        event->ignore();
    }
}

void DropFrame::dragLeaveEvent(QDragLeaveEvent *event) {
    event->accept();
}

void DropFrame::dropEvent(QDropEvent *event) {
    const QMimeData *mimeData = event->mimeData();
    if (mimeData->hasUrls()) {
        QList<QUrl> urls = mimeData->urls();
        for (const QUrl &url : urls) {
            QString filePath = url.toLocalFile();
            QString suffix = filePath.section(".",-1);
            qDebug()<<"suffix = "<<suffix;
            if(std::find(audio_Vec.begin(),audio_Vec.end(),suffix)!= audio_Vec.end()
                    || std::find(video_Vec.begin(),video_Vec.end(),suffix)!= video_Vec.end()){
                emit fileNameReady(filePath);
                break;
            }

        }
        event->acceptProposedAction();
    } else {
        event->ignore();
    }
}
